﻿using System;
using System.ComponentModel;

namespace HalconDotNet
{
	/// <summary>Represents an instance of a channel of an I/O device.</summary>
	// Token: 0x02000044 RID: 68
	public class HIOChannel : HHandle
	{
		// Token: 0x06000946 RID: 2374 RVA: 0x0000883B File Offset: 0x00006A3B
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HIOChannel() : base(HHandleBase.UNDEF)
		{
		}

		// Token: 0x06000947 RID: 2375 RVA: 0x0003C6EE File Offset: 0x0003A8EE
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HIOChannel(IntPtr handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x06000948 RID: 2376 RVA: 0x0003C6FD File Offset: 0x0003A8FD
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HIOChannel(HHandle handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x06000949 RID: 2377 RVA: 0x0003C70C File Offset: 0x0003A90C
		private void AssertSemType()
		{
			base.AssertSemType("io_channel");
		}

		// Token: 0x0600094A RID: 2378 RVA: 0x0003C719 File Offset: 0x0003A919
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HIOChannel obj)
		{
			obj = new HIOChannel(HHandleBase.UNDEF);
			return obj.Load(proc, parIndex, err);
		}

		// Token: 0x0600094B RID: 2379 RVA: 0x0003C734 File Offset: 0x0003A934
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HIOChannel[] obj)
		{
			HTuple htuple;
			err = HTuple.LoadNew(proc, parIndex, err, out htuple);
			obj = new HIOChannel[htuple.Length];
			for (int i = 0; i < htuple.Length; i++)
			{
				obj[i] = new HIOChannel(HalconAPI.IsLegacyHandleMode() ? htuple[i].IP : htuple[i].H);
			}
			htuple.Dispose();
			return err;
		}

		/// <summary>
		///   Open and configure I/O channels.
		///   Modified instance represents: Handles of the opened I/O channel.
		/// </summary>
		/// <param name="IODeviceHandle">Handle of the opened I/O device.</param>
		/// <param name="IOChannelName">HALCON I/O channel names of the specified device.</param>
		/// <param name="genParamName">Parameter names. Default: []</param>
		/// <param name="genParamValue">Parameter values. Default: []</param>
		// Token: 0x0600094C RID: 2380 RVA: 0x0003C7A4 File Offset: 0x0003A9A4
		public HIOChannel(HIODevice IODeviceHandle, string IOChannelName, HTuple genParamName, HTuple genParamValue)
		{
			IntPtr proc = HalconAPI.PreCall(2016);
			HalconAPI.Store(proc, 0, IODeviceHandle);
			HalconAPI.StoreS(proc, 1, IOChannelName);
			HalconAPI.Store(proc, 2, genParamName);
			HalconAPI.Store(proc, 3, genParamValue);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(genParamName);
			HalconAPI.UnpinTuple(genParamValue);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			GC.KeepAlive(IODeviceHandle);
		}

		/// <summary>Perform an action on I/O channels.</summary>
		/// <param name="IOChannelHandle">Handles of the opened I/O channels.</param>
		/// <param name="paramAction">Name of the action to perform.</param>
		/// <param name="paramArgument">List of arguments for the action. Default: []</param>
		/// <returns>List of values returned by the action.</returns>
		// Token: 0x0600094D RID: 2381 RVA: 0x0003C81C File Offset: 0x0003AA1C
		public static HTuple ControlIoChannel(HIOChannel[] IOChannelHandle, string paramAction, HTuple paramArgument)
		{
			HTuple htuple = HHandleBase.ConcatArray(IOChannelHandle);
			IntPtr proc = HalconAPI.PreCall(2010);
			HalconAPI.Store(proc, 0, htuple);
			HalconAPI.StoreS(proc, 1, paramAction);
			HalconAPI.Store(proc, 2, paramArgument);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(htuple);
			HalconAPI.UnpinTuple(paramArgument);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(IOChannelHandle);
			return result;
		}

		/// <summary>
		///   Perform an action on I/O channels.
		///   Instance represents: Handles of the opened I/O channels.
		/// </summary>
		/// <param name="paramAction">Name of the action to perform.</param>
		/// <param name="paramArgument">List of arguments for the action. Default: []</param>
		/// <returns>List of values returned by the action.</returns>
		// Token: 0x0600094E RID: 2382 RVA: 0x0003C888 File Offset: 0x0003AA88
		public HTuple ControlIoChannel(string paramAction, HTuple paramArgument)
		{
			IntPtr proc = HalconAPI.PreCall(2010);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, paramAction);
			HalconAPI.Store(proc, 2, paramArgument);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(paramArgument);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>Write a value to the specified I/O channels.</summary>
		/// <param name="IOChannelHandle">Handles of the opened I/O channels.</param>
		/// <param name="value">Write values.</param>
		/// <returns>Status of written values.</returns>
		// Token: 0x0600094F RID: 2383 RVA: 0x0003C8E8 File Offset: 0x0003AAE8
		public static HTuple WriteIoChannel(HIOChannel[] IOChannelHandle, HTuple value)
		{
			HTuple htuple = HHandleBase.ConcatArray(IOChannelHandle);
			IntPtr proc = HalconAPI.PreCall(2011);
			HalconAPI.Store(proc, 0, htuple);
			HalconAPI.Store(proc, 1, value);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(htuple);
			HalconAPI.UnpinTuple(value);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, HTupleType.INTEGER, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(IOChannelHandle);
			return result;
		}

		/// <summary>
		///   Write a value to the specified I/O channels.
		///   Instance represents: Handles of the opened I/O channels.
		/// </summary>
		/// <param name="value">Write values.</param>
		/// <returns>Status of written values.</returns>
		// Token: 0x06000950 RID: 2384 RVA: 0x0003C94C File Offset: 0x0003AB4C
		public HTuple WriteIoChannel(HTuple value)
		{
			IntPtr proc = HalconAPI.PreCall(2011);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, value);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(value);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, HTupleType.INTEGER, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>Read a value from the specified I/O channels.</summary>
		/// <param name="IOChannelHandle">Handles of the opened I/O channels.</param>
		/// <param name="status">Status of read value.</param>
		/// <returns>Read value.</returns>
		// Token: 0x06000951 RID: 2385 RVA: 0x0003C9A4 File Offset: 0x0003ABA4
		public static HTuple ReadIoChannel(HIOChannel[] IOChannelHandle, out HTuple status)
		{
			HTuple htuple = HHandleBase.ConcatArray(IOChannelHandle);
			IntPtr proc = HalconAPI.PreCall(2012);
			HalconAPI.Store(proc, 0, htuple);
			HalconAPI.InitOCT(proc, 0);
			HalconAPI.InitOCT(proc, 1);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(htuple);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			num = HTuple.LoadNew(proc, 1, HTupleType.INTEGER, num, out status);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(IOChannelHandle);
			return result;
		}

		/// <summary>
		///   Read a value from the specified I/O channels.
		///   Instance represents: Handles of the opened I/O channels.
		/// </summary>
		/// <param name="status">Status of read value.</param>
		/// <returns>Read value.</returns>
		// Token: 0x06000952 RID: 2386 RVA: 0x0003CA0C File Offset: 0x0003AC0C
		public HTuple ReadIoChannel(out HTuple status)
		{
			IntPtr proc = HalconAPI.PreCall(2012);
			base.Store(proc, 0);
			HalconAPI.InitOCT(proc, 0);
			HalconAPI.InitOCT(proc, 1);
			int num = HalconAPI.CallProcedure(proc);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			num = HTuple.LoadNew(proc, 1, HTupleType.INTEGER, num, out status);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>Set specific parameters of I/O channels.</summary>
		/// <param name="IOChannelHandle">Handles of the opened I/O channels.</param>
		/// <param name="genParamName">Parameter names. Default: []</param>
		/// <param name="genParamValue">Parameter values to set. Default: []</param>
		// Token: 0x06000953 RID: 2387 RVA: 0x0003CA68 File Offset: 0x0003AC68
		public static void SetIoChannelParam(HIOChannel[] IOChannelHandle, HTuple genParamName, HTuple genParamValue)
		{
			HTuple htuple = HHandleBase.ConcatArray(IOChannelHandle);
			IntPtr proc = HalconAPI.PreCall(2013);
			HalconAPI.Store(proc, 0, htuple);
			HalconAPI.Store(proc, 1, genParamName);
			HalconAPI.Store(proc, 2, genParamValue);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(htuple);
			HalconAPI.UnpinTuple(genParamName);
			HalconAPI.UnpinTuple(genParamValue);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(IOChannelHandle);
		}

		/// <summary>
		///   Set specific parameters of I/O channels.
		///   Instance represents: Handles of the opened I/O channels.
		/// </summary>
		/// <param name="genParamName">Parameter names. Default: []</param>
		/// <param name="genParamValue">Parameter values to set. Default: []</param>
		// Token: 0x06000954 RID: 2388 RVA: 0x0003CAC8 File Offset: 0x0003ACC8
		public void SetIoChannelParam(HTuple genParamName, HTuple genParamValue)
		{
			IntPtr proc = HalconAPI.PreCall(2013);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, genParamName);
			HalconAPI.Store(proc, 2, genParamValue);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(genParamName);
			HalconAPI.UnpinTuple(genParamValue);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>Query specific parameters of I/O channels.</summary>
		/// <param name="IOChannelHandle">Handles of the opened I/O channels.</param>
		/// <param name="genParamName">Parameter names. Default: "param_name"</param>
		/// <returns>Parameter values.</returns>
		// Token: 0x06000955 RID: 2389 RVA: 0x0003CB18 File Offset: 0x0003AD18
		public static HTuple GetIoChannelParam(HIOChannel[] IOChannelHandle, HTuple genParamName)
		{
			HTuple htuple = HHandleBase.ConcatArray(IOChannelHandle);
			IntPtr proc = HalconAPI.PreCall(2014);
			HalconAPI.Store(proc, 0, htuple);
			HalconAPI.Store(proc, 1, genParamName);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(htuple);
			HalconAPI.UnpinTuple(genParamName);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(IOChannelHandle);
			return result;
		}

		/// <summary>
		///   Query specific parameters of I/O channels.
		///   Instance represents: Handles of the opened I/O channels.
		/// </summary>
		/// <param name="genParamName">Parameter names. Default: "param_name"</param>
		/// <returns>Parameter values.</returns>
		// Token: 0x06000956 RID: 2390 RVA: 0x0003CB7C File Offset: 0x0003AD7C
		public HTuple GetIoChannelParam(string genParamName)
		{
			IntPtr proc = HalconAPI.PreCall(2014);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, genParamName);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>Close I/O channels.</summary>
		/// <param name="IOChannelHandle">Handles of the opened I/O channels.</param>
		// Token: 0x06000957 RID: 2391 RVA: 0x0003CBCC File Offset: 0x0003ADCC
		public static void CloseIoChannel(HIOChannel[] IOChannelHandle)
		{
			HTuple htuple = HHandleBase.ConcatArray(IOChannelHandle);
			IntPtr proc = HalconAPI.PreCall(2015);
			HalconAPI.Store(proc, 0, htuple);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(htuple);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(IOChannelHandle);
		}

		/// <summary>
		///   Close I/O channels.
		///   Instance represents: Handles of the opened I/O channels.
		/// </summary>
		// Token: 0x06000958 RID: 2392 RVA: 0x0003CC10 File Offset: 0x0003AE10
		public void CloseIoChannel()
		{
			IntPtr proc = HalconAPI.PreCall(2015);
			base.Store(proc, 0);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>Open and configure I/O channels.</summary>
		/// <param name="IODeviceHandle">Handle of the opened I/O device.</param>
		/// <param name="IOChannelName">HALCON I/O channel names of the specified device.</param>
		/// <param name="genParamName">Parameter names. Default: []</param>
		/// <param name="genParamValue">Parameter values. Default: []</param>
		/// <returns>Handles of the opened I/O channel.</returns>
		// Token: 0x06000959 RID: 2393 RVA: 0x0003CC44 File Offset: 0x0003AE44
		public static HIOChannel[] OpenIoChannel(HIODevice IODeviceHandle, HTuple IOChannelName, HTuple genParamName, HTuple genParamValue)
		{
			IntPtr proc = HalconAPI.PreCall(2016);
			HalconAPI.Store(proc, 0, IODeviceHandle);
			HalconAPI.Store(proc, 1, IOChannelName);
			HalconAPI.Store(proc, 2, genParamName);
			HalconAPI.Store(proc, 3, genParamValue);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(IOChannelName);
			HalconAPI.UnpinTuple(genParamName);
			HalconAPI.UnpinTuple(genParamValue);
			HIOChannel[] result;
			num = HIOChannel.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(IODeviceHandle);
			return result;
		}

		/// <summary>
		///   Open and configure I/O channels.
		///   Modified instance represents: Handles of the opened I/O channel.
		/// </summary>
		/// <param name="IODeviceHandle">Handle of the opened I/O device.</param>
		/// <param name="IOChannelName">HALCON I/O channel names of the specified device.</param>
		/// <param name="genParamName">Parameter names. Default: []</param>
		/// <param name="genParamValue">Parameter values. Default: []</param>
		// Token: 0x0600095A RID: 2394 RVA: 0x0003CCB4 File Offset: 0x0003AEB4
		public void OpenIoChannel(HIODevice IODeviceHandle, string IOChannelName, HTuple genParamName, HTuple genParamValue)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(2016);
			HalconAPI.Store(proc, 0, IODeviceHandle);
			HalconAPI.StoreS(proc, 1, IOChannelName);
			HalconAPI.Store(proc, 2, genParamName);
			HalconAPI.Store(proc, 3, genParamValue);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(genParamName);
			HalconAPI.UnpinTuple(genParamValue);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			GC.KeepAlive(IODeviceHandle);
		}
	}
}
